package com.kangye.enterprise.controller;

import com.kangye.enterprise.entity.Department;
import com.kangye.enterprise.entity.Items;
import com.kangye.enterprise.service.ItemsService;
import com.kangye.enterprise.util.ViewJsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: enterprise
 * @description:
 * @author: 索腾龙
 * @create: 2021-06-05 10:00
 **/
@Controller
public class ItemsController {
    //注入Service
    @Autowired
    private ItemsService itemsService;
    //跳转审核管理页面
    @RequestMapping("/selItem")
    public String selItem(){
        return "selItem";
    }
    //查询用户的所有需要审核的项目(索腾龙)
    @ResponseBody
    @RequestMapping("/selItemsList")
    public ViewJsonObject<Items> selItemsList(Integer page, Integer limit,Items items,String demoReload){
        //判断是否传参
        if (demoReload!=null){
            System.out.println(demoReload);
            //用数组形式分隔开
            String [] str = demoReload.split(",");
            //用循环去遍历里边的书
            for (int i = 0;i<str.length;i++){
                //如果长度等于2的时候 传两个参数
                if (str.length ==2){
                    items.setItemsName(str[0]);
                    items.setItemsDepartment(str[1]);
                    //如果长度等于1的时候 传一个参数
                }else if (str.length==1){
                    items.setItemsName(str[0]);
                }
            }
            return itemsService.selUser(page, limit,items);
        }else {
            return itemsService.selUser(page, limit,items);
        }
    }
    //查询全部部门
    @ResponseBody
    @RequestMapping("/selDepartments")
    public ViewJsonObject<Department> selDepartments(){
        return itemsService.selDepartments();
    }
}